﻿//百度地图 
// eg:BaiduMap("104.073065,30.689629", "104.073065,30.689629|104.071498,30.688708", "maps", 200, 100, "sysimages/custombaiduicon.png/custom_a_j.png", 27, 37, "1", "测试1|测试2", "测试1|测试2");
var BaiduMap = function (centeraddres, addresslist, contaier, infowindowwidth, infoheight, imgurl, imgwidth, imgheight, isanimation, title, content) {
    var list = addresslist.split('|');
    var lng = Number(centeraddres.split(',')[0]);
    var lat = Number(centeraddres.split(',')[1]);

    var map = new BMap.Map("" + contaier + "");            // 创建地图实例   
    map.centerAndZoom(new BMap.Point(lng, lat), 17); // 初始化地图，设置中心点坐标和地图级别 
    
    var mapStyle = {
        features: ["road", "building", "water", "land"],//隐藏地图上的poi
        style: "dark"  //设置地图风格为高端黑
    }

    function addMakerPoint(lng, lat, title, content, isopen) {
        var _point = new BMap.Point(lng, lat);
        var _marker = new BMap.Marker(_point);
        _marker.setTitle(title); //设置title
        if (isanimation == "1") {
            _marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
        }

        var opts = {
            width: infowindowwidth,     // 信息窗口宽度
            height: infoheight,     // 信息窗口高度
            title: "<b style=\"color:#cc5522; font-size:14px\">" + title + "</b>"  // 信息窗口标题
        }

        var infoWindow = new BMap.InfoWindow(content, opts);  // 创建信息窗口对象

        _marker.addEventListener("click", function () {
            this.openInfoWindow(infoWindow);
        });

        map.addOverlay(_marker);

        _marker.openInfoWindow(infoWindow);

    }

    for (var i = 0; i < list.length; i++) {

        if (list[i] != "") {

            var lng = Number(list[i].split(',')[0]);
            var lat = Number(list[i].split(',')[1]);
            if (i == 0) {
                addMakerPoint(lng, lat, title.split('|')[i], content.split('|')[i],"1"); //添加点
            }
            else {
                addMakerPoint(lng, lat, title.split('|')[i], content.split('|')[i],"0"); //添加点
            }

        }

    }

   // map.enableScrollWheelZoom();  // 开启鼠标滚轮缩放   
    map.enableKeyboard();         // 开启键盘控制   
    map.enableContinuousZoom();   // 开启连续缩放效果   
    map.enableInertialDragging(); // 开启惯性拖拽效果  

    map.addControl(new BMap.NavigationControl());               // 添加平移缩放控件
    map.addControl(new BMap.ScaleControl());                    // 添加比例尺控件
    map.addControl(new BMap.OverviewMapControl());              //添加缩略地图控件

 

}




